﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using DAL;

namespace BLL
{
    public class MajorService
    {
        MajorDAL majorDAL = new MajorDAL();

        public void CreateMajor(BoMajor major)
        {
            major.MAJ_ID = System.Guid.NewGuid().ToString();
            majorDAL.Insert(major);
        }

        public void UpdateMajor(BoMajor major)
        {
            majorDAL.Update(major);
        }

    
           // new BLL.ClassService().DeleteClassesByMajorId(maj_ID);
        public void DeleteMajor(BoMajor major)
        {
            if (new DbCommon.DbHelper().GetCount("Classes", "CLA_MAJOR='" + major.MAJ_ID + "'and CLA_IsShow='true'") > 0)
            {
                System.Windows.Forms.MessageBox.Show("该专业下还有班级，请先删除班级，再删除专业!");
            }
            else
            {
                majorDAL.Delete(major.MAJ_ID);
            }
        
        //new BLL.ClassService().DeleteClassesByMajorId(major.MAJ_ID);
           
        }
        public void DeleteMajorByAcademyId(string academyId)
        {
            BLL.ClassService classservice = new ClassService();
            IList<BoMajor> majorlist = GetMajorsByAcademy(academyId);
            majorDAL.DeleteMajorByAcademyId(academyId);
            foreach (BoMajor model in majorlist)
            {
                classservice.DeleteClassesByMajorId(model.MAJ_ID);
            }

        }

        public BoMajor GetMajor(string id)
        {
            return majorDAL.GetModel(id);
        }
        public List<BoMajor> GetMajorsByAcademy(string id)
        {
            return majorDAL.GetMajorsByAcademy(id);
        }

        /// <summary>
        /// 通过编号来获取专业
        /// </summary>
        /// <param name="Code"></param>
        /// <returns></returns>
        public List<BoMajor> GetMajorsByCode(string Code)
        {
            return majorDAL.GetMajorsByCode(Code);
        }

        /// <summary>
        /// 通过学院编号以及专业编号来获取专业信息
        /// </summary>
        /// <param name="MajorCode">专业编号</param>
        /// <param name="AcademyCode">学院编号</param>
        /// <returns>返回专业对象</returns>
        public BoMajor GetMajorByCodeAndAcaCode(string MajorCode, string AcademyCode)
        {
            return majorDAL.GetMajorByCodeAndAcaCode(MajorCode,AcademyCode);
        }

        public List<BoMajor> GetAllMajors()
        {
            return majorDAL.GetAllMajors();
        }

        /// <summary>
        /// 得到分页的数据列表
        /// </summary>
        /// <param name="orderCon">排序条件</param>
        /// <param name="sqlCon">查询条件</param>
        /// <param name="pagesize">每页显示大小</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="records">返回查询到的记录</param>
        /// <returns>返回对象列表</returns>
        public IList<BoMajor> getPageCompetitions(string sqlCon, string orderCon, int pagesize, int pageIndex, out int records)
        {
            return majorDAL.getPageCompetitions(sqlCon, orderCon, pagesize, pageIndex, out records);
        }

    }
}
